#include "main.h"

int main()
{
    char buf[100];
	char recieve[100] = {0};
    bzero(buf, 100);
    char ip[30];
	printf("this is a test program, input the content which you want to send to the server. input '#' to end the program\n");
	printf("input the server IP (e.g: 192.168.1.111):\n");
	scanf("%s", ip);
    struct sockaddr_in servaddr;
    int sockfd = Socket(AF_INET, SOCK_STREAM, 0);

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(5002);
    inet_pton(AF_INET, ip, &servaddr.sin_addr);

    Connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
	printf("connected!\n");
    strcpy(buf, "hehe");
    //send(sockfd, buf, 100, 0);
	//write(sockfd, "hahah", 5);
	while (scanf("%s", buf)) {
		if (buf[0] == '#') {
			Close(sockfd);
			break;		
		}
		write(sockfd, buf, strlen(buf));
		read(sockfd, recieve, 100);
		cout << recieve << endl;
		bzero(recieve, 100);	
	}
    return 0;
}
